<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul.li{
            list-style: none;
        }
        html,body{
            height: 100%;
        }
        body{
            display: flex;
            flex-direction: column;
        }
        header{
            height: 60px;
            background-color: #2980B9;
            color: white;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        header>h1{
            font-size: 16px;
            font-weight: normal;
        }
        header>div>.iconfont{
            margin-right: 5px;
        }
        main{
            flex: 1;
            display: flex;

            background-color: red;
        }
        main>.left{
            width: 150px;
            height: 100%;
            background-color: #2980B9;
            color: #ccc;

        }
        main>.left>li{
            height: 50px;
            text-align: center;
            line-height: 50px;
        }
        main>.left>li:nth-child(3){
            background-color: #1F618D;
            color: white;
        }
        main>.left>li>.iconfont{
            margin-right: 5px;

        }
        main>.right{
            flex: 1;
            background-color: white;
            padding: 40px;
            
        }
        main>.right>.serch>input{
            height: 38px;
            width: 300px;
            outline: none;
            text-indent: 20px;
         border: 1px solid #ccc;
            border-radius: 20px;
        }
        main>.right>.serch>button{
            margin-left: 30px;
            height: 40px;
            /* width: 100px; */
            padding: 0 30px;
            border-radius: 20px;
            border: none;
            color: white;
            background-color: #5DB85B;
        }
        main>.right>button{
            margin:20px 0;
            height: 40px;
              padding: 0 30px;
            border-radius: 20px;
            border: none;
            color: white;
            background-color: #5DB85B;
        }
        main>.right>table{
            width: 100%;
            text-align: center;
        }
        main>.right>table>tbody td{
            height: 50px;
          border-top: 1px solid;
        }
        main>.right>table tr td:first-child{
            text-align: left;
        }
        main>.right>table tr th:first-child{
            text-align: left;
        }
        main>.right>table>tbody>tr>td:nth-child(6)>span{
            background-color: #5DB85B;
            color: white;
            width: 50px;
            padding: 5px;
            border-radius: 5px;
        }
        .huan{
            display: flex;
            justify-content: center;
        }
        .huan>button{
            margin: 5px;
        }
    </style>
    <link rel="stylesheet" href="./font/iconfont.css">
</head>
<body>
    <header>
        <h1>9966云专题</h1>
        <div>
            <span class="iconfont icon-yonghu"></span>
            <span><span class="name">龙马</span>（9996 云专题）</span>
        </div>
    </header>
    <main>
        <ul class="left">
            <li>
                <span class="iconfont icon-home"></span>
                首页
            </li>
            <li>
                <span class="iconfont icon-zhuantiguanli"></span>
                专题
            </li>
            <li>
                <span class="iconfont icon-yonghu"></span>
                用户
            </li>
            <li>
                <span class="iconfont icon-shezhi"></span>
             设置
            </li>
            <li>
                <span class="iconfont icon-xitongrizhi"></span>
                日志
            </li>
          
        </ul>
        <div class="right">
            <div class="serch">
                <input type="text" name="" placeholder="搜索用户" id="">
                <button>搜索</button>
            </div>
            <button><span class="iconfont icon-tianjia"></span> 添加用户</button>
            <table >
                <thead>
                    <tr>
                        <th>邮箱（用户）</th>
                        <th>姓名</th>
                        <th>电话</th>
                        <th>所属组</th>
                        <th>管理员</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                   
                </tbody>
            </table>
            <div class="huan">
                <button>上一页</button>
                <button>下一页</button>
            </div>
        </div>
    </main>
</body>
</html>
<script src="./axios.min.js"></script>
<script>
    var sout=document.querySelector(' main>.right>.serch>input')
    var sou=document.querySelector(' main>.right>.serch>button')
    var tbody=document.querySelector('tbody')
   var shang=document.querySelector('.huan>button')
   var xia=document.querySelector('.huan>button:last-child')
   var current=1
   var count=3
   var total
  if(localStorage.getItem('yonghu')){
    document.querySelector('header .name').innerHTML=`${JSON.parse(localStorage.getItem('yonghu')).name}`
  }
    function render(shuzu){
        if(current==1){
            shang.disabled=true
        }else{
            shang.disabled=false
        }
        if(current==total){
            xia.disabled=true
        }else{
            xia.disabled=false
        }

        var str=''
        str=shuzu.map((item)=>{
            return `
            <tr>
                        <td>${item.email}</td>
                        <td>${item.name}</td>
                        <td>${item.phone}</td>
                        <td>${item.ingroup}</td>
                        <td>${item.isguanli ? '是' : '否'}</td>
                        <td>
                            <span style="background-color: ${item.zhuangtai ? 'green' : 'red'};" >${item.zhuangtai ? '正常' : '异常'}</span>
                        </td>
                        <td>
                            <span class="iconfont icon-shanchu" data-phone=${item.phone}></span>
                            <span class="iconfont icon-bianji"></span>
                        </td>
                    </tr>
            
            `
        }).join("")

        tbody.innerHTML= str ? str : `<ul style="text-align:center;color:red;">未找到相关用户</ul>`
    }
    axios.get('/user/xuan',{params:{current:1,count:count}}).then((res)=>{
        console.log(res.data)
        total=Math.ceil(res.data.total/count)
        render(res.data.list)
    })
    sou.onclick=function(){
        if(sout.value==''){
            return
        }
        axios.get('/user/cha',{params:{gjc:sout.value}}).then((res)=>{
        console.log(res.data)
        
        render(res.data.list)
    })
    }
    shang.onclick=function(){
        current--
        axios.get('/user/xuan',{params:{current:current,count:count}}).then((res)=>{
        console.log(res.data)
        render(res.data.list)
    })
    }
    xia.onclick=function(){
        current++
        axios.get('/user/xuan',{params:{current:current,count:count}}).then((res)=>{
        console.log(res.data)
        render(res.data.list)
    })
    }
    document.querySelector('tbody').onclick=function(e){
        if(e.target.classList.contains('icon-shanchu')==true){
            
            axios.post('/user/delete',{phone:e.target.dataset.phone}).then((res)=>{
                console.log(res.data)
                total=Math.ceil(res.data.total/count)
                render(res.data.list)
            })
        }
    }
</script>